﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentCourses
{
    class Course
    {
        private const int maxNumberOfStudents = 29;

        private string name;
        private string id;
        private HashSet<Student> students;

        public string Name
        {
            get { return name; }
            private set
            {
               //if (value == null || value == "")
               // {
               //     throw new ArgumentNullException("Name can not be null or empty.");
               // }
                name = value;
            }
        }
       
        public string Id
        {
          get { return id; }
          set { id = value; }
        }
        
        public HashSet<Student> Students
        {
            get { return students; }
        }

        public Course(string name, string id)
        {
            this.Name = name;
            this.Id = id;
            students = new HashSet<Student>();
        }

        public void AddStudent(Student newStudent)
        {
            if (students.Count >= maxNumberOfStudents)
            {
                throw new OverflowException("Students in a course should be less than " + maxNumberOfStudents + 1);
            }
            if (students.Contains(newStudent))
            {
                throw new ArgumentException("This student is already attending this course.");
            }
            students.Add(newStudent);
        }

        public void RemoveStudent(Student oldStudent)
        {
            if (!students.Contains(oldStudent))
            {
                throw new ArgumentException("Can't remove student, who is not attending the course.");
            }
            students.Remove(oldStudent);
        }
    }
}
